//
//  MyTableViewController.m
//  bh
//
//  Created by lanou on 15/12/24.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "MyTableViewController.h"
#import "MyTableViewCell.h"
#import "MyViewController.h"
@interface MyTableViewController ()<UITableViewDataSource,UITableViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property (nonatomic, strong) NSArray *array;
@property (nonatomic, strong) UIImageView *pictureView;

@end

@implementation MyTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *headerView = [[UIView alloc]initWithFrame:(CGRectMake(0, 0, kWidth, kHeight / 4))];
    headerView.backgroundColor = [UIColor orangeColor];
    _pictureView = [[UIImageView alloc]initWithFrame:(CGRectMake(15, 40, kHeight / 6, kHeight / 6))];
    _pictureView.layer.masksToBounds = YES;
    _pictureView.layer.borderWidth = 2;
    _pictureView.layer.cornerRadius = _pictureView.bounds.size.height / 2;
  
    _pictureView.layer.borderColor = [[UIColor whiteColor]CGColor];
    _pictureView.image = [UIImage imageNamed:@"ic_blank_collect@3x.png"];
    [headerView addSubview:_pictureView];
    
    UILabel *nameLabel = [[UILabel alloc]initWithFrame:(CGRectMake(kHeight / 5 + 10, kHeight / 12, kWidth / 3, 40))];
    nameLabel.backgroundColor = [UIColor redColor];
    nameLabel.font = [UIFont boldSystemFontOfSize:22];
    nameLabel.textColor = [UIColor whiteColor];
    [headerView addSubview:nameLabel];
    
    UILabel *addLabel = [[UILabel alloc]initWithFrame:(CGRectMake(kHeight / 5 + 10, kHeight / 12 + 40, kWidth / 3, 30))];
    addLabel.backgroundColor = [UIColor whiteColor];
    addLabel.font = [UIFont systemFontOfSize:18];
    addLabel.textColor = [UIColor whiteColor];
    [headerView addSubview:addLabel];
    
    // 表头
    self.tableView.tableHeaderView = headerView;
    
    // 注册单元格
    [self.tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"cell1"];
    
    // 给图片添加点击事件
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(qiehuantupian)];
    _pictureView.userInteractionEnabled = YES;
    [_pictureView addGestureRecognizer:tap];
    
    self.tableView.separatorStyle = UITableViewCellAccessoryNone;
    
    
    
    
    
    
    
    
    
    
    
    
    
}

// 图片点击事件
- (void)qiehuantupian {
    UIImagePickerController *imagePC = [[UIImagePickerController alloc]init];
    
    imagePC.delegate = self;
    
    imagePC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    
    
    [self presentViewController:imagePC animated:YES completion:nil];
}

//协议方法(???????)

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    //获取图片
    UIImage *image =[info objectForKey:UIImagePickerControllerOriginalImage];
    //赋值
    _pictureView.image = image;
    
    //
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1" forIndexPath:indexPath];
    
    if (indexPath.row == 0) {
        cell.label.text = @"我的收藏";
       
    }else if (indexPath.row == 1){
        cell.label.text = @"二维码扫描";
        
    } else {
        cell.label.text = @"切换账号";
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 80;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        NSLog(@"111");
        
    }else if (indexPath.row == 1){
        MyViewController *MyVC = [[MyViewController alloc]init];
        [self.navigationController pushViewController:MyVC animated:YES];
    } else {
        NSLog(@"333");
    }
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
